package com.lytis.zoovideo.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @author :DongPeiLei
 * @description :
 * @create :2022-05-30 14:25:00
 */
@Component
public class DateTimeHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        this.setFieldValByName("createdAt", LocalDateTime.now(), metaObject);
        this.setFieldValByName("updatedAt", LocalDateTime.now(), metaObject);
//        this.strictInsertFill(metaObject, "createdAt", () -> LocalDateTime.now(), LocalDateTime.class);
//        this.strictInsertFill(metaObject, "updatedAt", () -> LocalDateTime.now(), LocalDateTime.class);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "updatedAt", () -> LocalDateTime.now(), LocalDateTime.class);
        this.setFieldValByName("updatedAt", LocalDateTime.now(), metaObject);
    }
}
